package com.dc.ai.security.model;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import com.dc.ai.entity.dto.UserAuthInfo;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.Collections;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * Spring Security 用户对象
 * @author zhangpan
 */
@Data
@NoArgsConstructor
public class SysUserDetails implements UserDetails {

    private String userId;

    private String openId;
    private String username;

    private String password;

    private Boolean enabled;


    public SysUserDetails(UserAuthInfo user) {
        this.userId = user.getUserId();
        this.username = user.getUsername();
        this.openId = user.getOpenId();
        this.password = user.getPassword();
        this.enabled = ObjectUtil.equal(user.getStatus(), 1);

    }

    public String getUserId() {
        return this.userId;
    }


    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return  Collections.EMPTY_SET;
    }

    @Override
    public String getPassword() {
        return this.password;
    }

    @Override
    public String getUsername() {
        return this.username;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return this.enabled;
    }
}

